package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Taste;
import com.noahplat.person.service.TasteService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: TasteController
 * @Description: 口味偏好controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/taste")
@Validated
public class TasteController {

    @Autowired
    private TasteService tasteService;

    /**
     * 获取口味偏好
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:getTaste')")
    @GetMapping("/getTaste")
    public Result getTaste(){
        return tasteService.getTaste();
    }

    /**
     * 添加口味偏好
     * @param taste
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:addTaste')")
    @PostMapping("/addTaste")
    public Result addTaste(@RequestBody Taste taste){
        return tasteService.addTaste(taste);
    }
    /**
     * 修改口味偏好
     * @param taste
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:updateTaste')")
    @PutMapping("/updateTaste")
    public Result updateTaste(@RequestBody Taste taste){
        return tasteService.updateTaste(taste);
    }
    /**
     * 删除口味偏好
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:delTaste')")
    @DeleteMapping("/delTaste")
    public Result delTaste(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return tasteService.delTaste(id);
    }
    /**
     * 分页获取口味偏好
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:getAdminTaste')")
    @GetMapping("/getAdminTaste")
    public Result getAdminTaste(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return tasteService.getAdminTaste(page, limit);
    }
    /**
     * 获取口味偏好详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:TasteController:getTasteById')")
    @GetMapping("/getTasteById")
    public Result getTasteById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return tasteService.getTasteById(id);
    }
}
